package cn.bugstack.xfg.dev.tech.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {


    @Autowired
    MyPasswordEncoder myPasswordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        if ("admin".equals(username)) {
//            return User.withUsername("admin")
//                    .password("{noop}password")
//                    .roles("ADMIN")
//                    .build();
//        }
//        throw new UsernameNotFoundException("User not found");

        MyUserDetails myUserDetails = new MyUserDetails();
        myUserDetails.setUsername("tanxi");
    //    myUserDetails.setPassword("tx1234");

        String encodePassword = myPasswordEncoder.encode("tx1234");
        myUserDetails.setPassword(encodePassword);
        return myUserDetails;

    }
}

